<?php

/**
 * 短视频
 */
class Api_Video extends PhalApi_Api
{
	
	public function getRules()
	{
		return array(
			'getCon' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
			),
			
			'setVideo'   => array(
				'uid'      => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
				'token'    => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户Token'),
				'title'    => array('name' => 'title', 'type' => 'string', 'desc' => '标题'),
				'thumb'    => array('name' => 'thumb', 'type' => 'string', 'require' => true, 'desc' => '封面图'),
				'href'     => array('name' => 'href', 'type' => 'string', 'require' => true, 'desc' => '视频链接'),
				'href_w'   => array('name' => 'href_w', 'type' => 'string', 'desc' => '水印视频链接'),
				'lat'      => array('name' => 'lat', 'type' => 'string', 'desc' => '维度'),
				'lng'      => array('name' => 'lng', 'type' => 'string', 'desc' => '经度'),
				'city'     => array('name' => 'city', 'type' => 'string', 'desc' => '城市'),
				'music_id' => array('name' => 'music_id', 'type' => 'int', 'default' => 0, 'desc' => '背景音乐id'),
				'type'     => array('name' => 'type', 'type' => 'int', 'default' => 0, 'desc' => '绑定的内容类型 0 没绑定 1 自己商品 2 付费内容 3代售商品'),
				'goodsid'  => array('name' => 'goodsid', 'type' => 'int', 'default' => 0, 'desc' => '商品ID'),
				'classid'  => array('name' => 'classid', 'type' => 'int', 'default' => 0, 'desc' => '视频分类ID'),
				'anyway'   => array('name' => 'anyway', 'type' => 'string', 'default' => '1.1', 'desc' => '横竖屏(封面-高/宽)，大于1表示竖屏,小于1表示横屏'),
			),
			'setComment' => array(
				'uid'       => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
				'token'     => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户Token'),
				'videoid'   => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
				'touid'     => array('name' => 'touid', 'type' => 'int', 'default' => 0, 'desc' => '回复的评论UID'),
				'commentid' => array('name' => 'commentid', 'type' => 'int', 'default' => 0, 'desc' => '回复的评论commentid'),
				'parentid'  => array('name' => 'parentid', 'type' => 'int', 'default' => 0, 'desc' => '回复的评论ID'),
				'content'   => array('name' => 'content', 'type' => 'string', 'default' => '', 'desc' => '内容'),
				'at_info'   => array('name' => 'at_info', 'type' => 'string', 'desc' => '被@的用户json信息'),
			),
			'addView'    => array(
				'uid'        => array('name' => 'uid', 'type' => 'int', 'require' => true, 'desc' => '用户ID'),
				'token'      => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户Token'),
				'videoid'    => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
				'random_str' => array('name' => 'random_str', 'type' => 'string', 'require' => true, 'desc' => '加密串'),
			
			),
			'addLike'    => array(
				'uid'     => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
				'token'   => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户Token'),
				'videoid' => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
			),
			'addStep'    => array(
				'uid'     => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
				'videoid' => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
			),
			
			'addShare' => array(
				'uid'        => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'videoid'    => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
				'random_str' => array('name' => 'random_str', 'type' => 'string', 'require' => true, 'desc' => '加密串'),
			),
			
			'setBlack' => array(
				'uid'     => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
				'videoid' => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
			),
			
			'addCommentLike'    => array(
				'uid'       => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
				'token'     => array('name' => 'token', 'type' => 'string', 'require' => false, 'desc' => '用户Token'),
				'commentid' => array('name' => 'commentid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '评论/回复 ID'),
			),
			'getVideoList'      => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'p'   => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default' => 1, 'desc' => '页数'),
			),
			'getAttentionVideo' => array(
				'uid'   => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'require' => false, 'desc' => '用户Token'),
				'p'     => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default' => 1, 'desc' => '页数'),
			),
			'getVideo'          => array(
				'uid'     => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'videoid' => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
			),
			'getComments'       => array(
				'uid'     => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'videoid' => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
				'p'       => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default' => 1, 'desc' => '页数'),
			),
			
			'getReplys' => array(
				'uid'       => array('name' => 'uid', 'type' => 'int', 'require' => true, 'desc' => '用户ID'),
				'commentid' => array('name' => 'commentid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '评论ID'),
				'p'         => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default' => 1, 'desc' => '页数'),
			),
			
			'getMyVideo' => array(
				'uid'   => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户Token'),
				'p'     => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default' => 1, 'desc' => '页数'),
			),
			'del'        => array(
				'uid'     => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
				'token'   => array('name' => 'token', 'type' => 'string', 'min' => 1, 'require' => true, 'desc' => 'token'),
				'videoid' => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
			),
			
			'report' => array(
				'uid'     => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
				'token'   => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => 'token'),
				'videoid' => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
				'content' => array('name' => 'content', 'type' => 'string', 'min' => 1, 'require' => true, 'desc' => '举报内容'),
			),
			
			'getHomeVideo'                  => array(
				'uid'   => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'touid' => array('name' => 'touid', 'type' => 'int', 'require' => true, 'desc' => '对方ID'),
				'p'     => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default' => 1, 'desc' => '页数'),
			),
			'getCreateNonreusableSignature' => array(
				'imgname'     => array('name' => 'imgname', 'type' => 'string', 'desc' => '图片名称'),
				'videoname'   => array('name' => 'videoname', 'type' => 'string', 'desc' => '视频名称'),
				'folderimg'   => array('name' => 'folderimg', 'type' => 'string', 'desc' => '图片文件夹'),
				'foldervideo' => array('name' => 'foldervideo', 'type' => 'string', 'desc' => '视频文件夹'),
			),
			
			'getNearby' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'lng' => array('name' => 'lng', 'type' => 'string', 'desc' => '经度值'),
				'lat' => array('name' => 'lat', 'type' => 'string', 'desc' => '纬度值'),
				'p'   => array('name' => 'p', 'type' => 'int', 'default' => '1', 'desc' => '页数'),
			),
			
			'setConversion' => array(
				'uid'        => array('name' => 'uid', 'type' => 'int', 'require' => true, 'desc' => '用户ID'),
				'token'      => array('name' => 'token', 'type' => 'string', 'min' => 1, 'require' => true, 'desc' => 'token'),
				'videoid'    => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
				'random_str' => array('name' => 'random_str', 'type' => 'string', 'require' => true, 'desc' => '加密串'),
			),
			
			'getClassVideo' => array(
				'videoclassid' => array('name' => 'videoclassid', 'type' => 'int', 'default' => '0', 'desc' => '视频分类ID'),
				'uid'          => array('name' => 'uid', 'type' => 'int', 'require' => true, 'desc' => '用户ID'),
				'p'            => array('name' => 'p', 'type' => 'int', 'default' => '1', 'desc' => '页数'),
			),
			
			'startWatchVideo' => array(
				'uid'   => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '会员ID'),
				'token' => array('name' => 'token', 'require' => true, 'min' => 1, 'desc' => '会员token'),
			),
			
			'endWatchVideo' => array(
				'uid'   => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '会员ID'),
				'token' => array('name' => 'token', 'require' => true, 'min' => 1, 'desc' => '会员token'),
			),
			'delComments'   => array(
				'uid'        => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token'      => array('name' => 'token', 'type' => 'string', 'require' => false, 'desc' => '用户Token'),
				'videoid'    => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
				'commentid'  => array('name' => 'commentid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '评论ID'),
				'commentuid' => array('name' => 'commentuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '评论者用户ID'),
			
			),
		
		
		);
	}
	
	/**
	 * 获取视频配置
	 * @desc 用于获取视频配置
	 * @return int code 操作码，0表示成功
	 * @return array info
	 * @return string info[0].isshop 是否有店铺，0否1是
	 * @return string msg 提示信息
	 */
	public function getCon()
	{
		$uid    = checkNull($this->uid);
		$isshop = 1;
		
		// 店铺是否开通
		$is_shop = checkShopIsPass($uid);
		//付费内容是否开通
		$is_paidprogram = checkPaidProgramIsPass($uid);
		if(!$is_shop && !$is_paidprogram){
			$isshop = 0;
		}
		
		$cdnset['isshop'] = $isshop;
		
		return $this->success(['0' => $cdnset]);
	}
	
	/**
	 * 发布短视频
	 * @desc 用于发布短视频
	 * @return int code 操作码，0表示成功
	 * @return array info
	 * @return string info[0].id 视频记录ID
	 * @return string msg 提示信息
	 */
	public function setVideo()
	{
		$uid      = checkNull($this->uid);
		$token    = checkNull($this->token);
		$title    = checkNull($this->title);
		$thumb    = checkNull($this->thumb);
		$href     = checkNull($this->href);
		$href_w   = checkNull($this->href_w);
		$lat      = checkNull($this->lat);
		$lng      = checkNull($this->lng);
		$city     = checkNull($this->city);
		$music_id = checkNull($this->music_id);
		$type     = checkNull($this->type);
		$goodsid  = checkNull($this->goodsid);
		$classid  = checkNull($this->classid);//视频分类ID
		$anyway   = checkNull($this->anyway);
		
		if($classid < 1){
			return $this->fail('请选择分类!', 10012);
		}
		
		$checkToken = checkToken($uid, $token);
		if($checkToken == 700){
			return $this->fail('您的登陆状态失效，请重新登陆！', $checkToken);
		}
		
		$sensitivewords = sensitiveField($title);
		if($sensitivewords == 1001){
			return $this->fail('输入非法，请重新输入!', 10011);
		}
		
		$thumb_s = '';
		if($thumb){
			$configpri = getConfigPri();
			$cloudtype = $configpri['cloudtype'];
			if($cloudtype == 1){ //七牛云存储
				$thumb_s = $thumb.'?imageView2/2/w/200/h/200';
			} else{
				$thumb_s = $thumb;
			}
		}
		
		
		$data = array(
			"uid"      => $uid,
			"title"    => $title,
			"thumb"    => $thumb,
			"thumb_s"  => $thumb_s,
			"href"     => $href,
			"href_w"   => $href_w,
			"lat"      => $lat,
			"lng"      => $lng,
			"city"     => $city,
			"likes"    => 0,
			"views"    => 1, //因为涉及到推荐排序问题，所以初始值要为1
			"comments" => 0,
			"addtime"  => time(),
			"music_id" => $music_id,
			"classid"  => $classid,
			"anyway"   => $anyway,
		);
		if($type > 0){
			//商品
			if($type == 1 && $goodsid > 0){
				$domain2  = new Domain_Shop();
				$where    = ['id' => $goodsid];
				$goodinfo = $domain2->getGoods($where);
				if(!$goodinfo){
					return $this->fail('商品不存在!', 1006);
				}
				if($goodinfo['uid'] != $uid){
					return $this->fail('非本人商品!', 1002);
				}
				if($goodinfo['status'] == -2){
					return $this->fail('该商品已被下架!', 1003);
				}
				if($goodinfo['status'] == -1){
					return $this->fail('该商品已下架!', 1004);
				}
				if($goodinfo['status'] != 1){
					return $this->fail('该商品未通过审核!', 1005);
				}
				
				$data['type']    = $type;
				$data['goodsid'] = $goodsid;
			} elseif($type == 2 && $goodsid > 0){
				//付费内容
				$domain3          = new Domain_Paidprogram();
				$where            = ['id' => $goodsid];
				$paidprogram_info = $domain3->getPaidProgram($where);
				if(!$paidprogram_info){
					return $this->fail('付费内容不存在!', 1007);
				}
				if($paidprogram_info['uid'] != $uid){
					return $this->fail('非本人发布的付费内容!', 1008);
				}
				if($paidprogram_info['status'] != 1){
					return $this->fail('该付费内容未通过审核!', 1009);
				}
				
				$data['type']    = $type;
				$data['goodsid'] = $goodsid;
				
			} elseif($type == 3 && $goodsid > 0){
				//代售的平台商品
				$domain2  = new Domain_Shop();
				$where    = ['id' => $goodsid];
				$goodinfo = $domain2->getGoods($where);
				if(!$goodinfo){
					return $this->fail('商品不存在!', 1006);
				}
				
				//判断是否是代售商品
				$where           = [];
				$where['uid']    = $uid;
				$where['status'] = 1;
				$is_sale         = checkUserSalePlatformGoods($where);
				if(!$is_sale){
					return $this->fail('未代售该商品!', 1008);
				}
				
				$data['type']    = 1;
				$data['goodsid'] = $goodsid;
			}
		}
		
		
		$domain = new Domain_Video();
		$info   = $domain->setVideo($data, $music_id);
		if($info == 1007){
			return $this->fail('视频分类不存在!', 1007);
		} elseif(!$info){
			return $this->fail('发布失败!', 1001);
		}
		
		$info['thumb_s'] = get_upload_path($thumb_s);
		$info['title']   = $title;
		
		return $this->success(['0' => $info]);
	}
	
	/**
	 * 评论/回复
	 * @desc 用于用户评论/回复 别人视频
	 * @return int code 操作码，0表示成功
	 * @return array info
	 * @return int info[0].isattent 对方是否关注我
	 * @return int info[0].u2t 我是否拉黑对方
	 * @return int info[0].t2u 对方是否拉黑我
	 * @return int info[0].comments 评论总数
	 * @return int info[0].replys 回复总数
	 * @return string msg 提示信息
	 */
	public function setComment()
	{
		$uid       = checkNull($this->uid);
		$token     = checkNull($this->token);
		$touid     = checkNull($this->touid);
		$videoid   = checkNull($this->videoid);
		$commentid = checkNull($this->commentid);
		$parentid  = checkNull($this->parentid);
		$content   = checkNull($this->content);
		$at_info   = $this->at_info;
		
		if(!$at_info){
			$at_info = '';
		}
		
		$checkToken = checkToken($uid, $token);
		if($checkToken == 700){
			return $this->fail('您的登陆状态失效，请重新登陆！', $checkToken);
		}
		
		$sensitivewords = sensitiveField($content);
		if($sensitivewords == 1001){
			return $this->fail('输入非法，请重新输入!', 10011);
		}
		if($commentid == 0 && $commentid != $parentid){
			$commentid = $parentid;
		}
		
		$data   = array(
			'uid'       => $uid,
			'touid'     => $touid,
			'videoid'   => $videoid,
			'commentid' => $commentid,
			'parentid'  => $parentid,
			'content'   => $content,
			'addtime'   => time(),
			'at_info'   => urldecode($at_info),
		);
		$domain = new Domain_Video();
		$result = $domain->setComment($data);
		if($result == 1001){
			return $this->fail('评论失败!', 1001);
		}
		
		$info = array('isattent' => '0', 'u2t' => '0', 't2u' => '0', 'comments' => $result['comments'], 'replys' => $result['replys'],);
		if($touid > 0){
			$isattent = isAttention($touid, $uid);
			$u2t      = isBlack($uid, $touid);
			$t2u      = isBlack($touid, $uid);
			
			$info['isattent'] = (string)$isattent;
			$info['u2t']      = (string)$u2t;
			$info['t2u']      = (string)$t2u;
		}
		
		$msg = '评论成功';
		if($parentid != 0){
			$msg = '回复成功';
		}
		
		return $this->success(['0' => $info], $msg);
	}
	
	/**
	 * 阅读
	 * @desc 用于视频阅读数累计
	 * @return int code 操作码，0表示成功
	 * @return string msg 提示信息
	 */
	public function addView()
	{
		$uid        = checkNull($this->uid);
		$token      = checkNull($this->token);
		$videoid    = checkNull($this->videoid);
		$random_str = checkNull($this->random_str);
		
		//md5加密验证字符串
		$str = md5($uid.'-'.$videoid.'-'.'#2hgfk85cm23mk58vncsark');
		if($random_str !== $str){
			return $this->fail('更新视频阅读次数失败!', 1001);
		}
		
		$checkToken = checkToken($uid, $token);
		if($checkToken == 700){
			return $this->fail('您的登陆状态失效，请重新登陆！', $checkToken);
		}
		
		$domain = new Domain_Video();
		$res    = $domain->addView($uid, $videoid);
		
		return $this->success([], '更新视频阅读次数成功!');
	}
	
	/**
	 * 点赞
	 * @desc 用于视频点赞数累计
	 * @return int code 操作码，0表示成功
	 * @return array info
	 * @return string info[0].islike 是否点赞
	 * @return string info[0].likes 点赞数量
	 * @return string msg 提示信息
	 */
	public function addLike()
	{
		$uid     = checkNull($this->uid);
		$token   = checkNull($this->token);
		$videoid = checkNull($this->videoid);
		$isBan   = isBan($uid);
		if($isBan == '0'){
			return $this->fail('该账号已被禁用!', 700);
		}
		
		$checkToken = checkToken($uid, $token);
		if($checkToken == 700){
			return $this->fail('您的登陆状态失效，请重新登陆！', $checkToken);
		}
		
		$domain = new Domain_Video();
		$result = $domain->addLike($uid, $videoid);
		if($result == 1001){
			return $this->fail('视频已删除!', 1001);
		} elseif($result == 1002){
			return $this->fail('不能给自己点赞!', 1002);
		}
		
		return $this->success(['0' => $result], '点赞成功!');
	}
	
	/**
	 * 踩一下
	 * @desc 用于视频踩数累计
	 * @return int code 操作码，0表示成功
	 * @return array info
	 * @return string info[0].isstep 是否踩
	 * @return string info[0].steps 踩数量
	 * @return string msg 提示信息
	 */
	public function addStep()
	{
		$uid     = checkNull($this->uid);
		$videoid = checkNull($this->videoid);
		$isBan   = isBan($uid);
		if($isBan == '0'){
			return $this->fail('该账号已被禁用!', 700);
		}
		
		$domain = new Domain_Video();
		$result = $domain->addStep($uid, $videoid);
		
		return $this->success(['0' => $result], '踩一踩成功!');
	}
	
	/**
	 * 视频分享
	 * @desc 用于视频分享数累计
	 * @return int code 操作码，0表示成功
	 * @return array info
	 * @return string info[0].isshare 是否分享
	 * @return string info[0].shares 分享数量
	 * @return string msg 提示信息
	 */
	public function addShare()
	{
		$uid        = checkNull($this->uid);
		$videoid    = checkNull($this->videoid);
		$random_str = checkNull($this->random_str);
		
		//md5加密验证字符串
		$str = md5($uid.'-'.$videoid.'-'.'#2hgfk85cm23mk58vncsark');
		if($random_str != $str){
			return $this->fail('视频分享数修改失败!', 1001);
		}
		
		$domain = new Domain_Video();
		$result = $domain->addShare($uid, $videoid);
		
		return $this->success(['0' => $result], '分享成功!');
	}
	
	/**
	 * 拉黑视频
	 * @desc 用于拉黑视频
	 * @return int code 操作码，0表示成功
	 * @return array info
	 * @return string info[0].isblack 是否拉黑
	 * @return string msg 提示信息
	 */
	public function setBlack()
	{
		$uid     = checkNull($this->uid);
		$videoid = checkNull($this->videoid);
		$isBan   = isBan($uid);
		if($isBan == '0'){
			return $this->fail('该账号已被禁用!', 700);
		}
		
		$domain = new Domain_Video();
		$result = $domain->setBlack($uid, $videoid);
		
		return $this->success(['0' => $result], '操作成功!');
	}
	
	/**
	 * 评论/回复 点赞
	 * @desc 用于评论/回复 点赞数累计
	 * @return int code 操作码，0表示成功
	 * @return array info
	 * @return string info[0].islike 是否点赞
	 * @return string info[0].likes 点赞数量
	 * @return string msg 提示信息
	 */
	public function addCommentLike()
	{
		$uid       = checkNull($this->uid);
		$token     = checkNull($this->token);
		$commentid = checkNull($this->commentid);
		$isBan     = isBan($uid);
		if($isBan == '0'){
			return $this->fail('该账号已被禁用!', 700);
		}
		
		$checkToken = checkToken($uid, $token);
		if($checkToken == 700){
			return $this->fail('您的登陆状态失效，请重新登陆！', $checkToken);
		}
		
		$domain = new Domain_Video();
		$result = $domain->addCommentLike($uid, $commentid);
		if($result == 1001){
			return $this->fail('评论信息不存在!', 1001);
		}
		
		return $this->success(['0' => $result], '操作成功!');
	}
	
	/**
	 * 获取app首页视频
	 * @desc 用于获取app首页视频
	 * @return int code 操作码，0表示成功
	 * @return array info 视频列表
	 * @return object info[].userinfo 用户信息
	 * @return string info[].datetime 格式后的发布时间
	 * @return string info[].islike 是否点赞
	 * @return string info[].isattent 是否关注
	 * @return string info[].thumb_s 封面小图，分享用
	 * @return string info[].comments 评论总数
	 * @return string info[].likes 点赞数
	 * @return string info[].goodsid 商品ID，0为无商品
	 * @return object info[].goodsinfo 商品信息
	 * @return string info[].goodsinfo.name 名称
	 * @return string info[].goodsinfo.href 链接
	 * @return string info[].goodsinfo.thumb 图片
	 * @return string info[].goodsinfo.old_price 原价
	 * @return string info[].goodsinfo.price 现价
	 * @return string info[].goodsinfo.des 介绍
	 * @return string msg 提示信息
	 */
	public function getVideoList()
	{
		$uid = checkNull($this->uid);
		$p   = checkNull($this->p);
		if($uid > 0){
			$isBan = isBan($this->uid);
			if($isBan == '0'){
				return $this->fail('该账号已被禁用!', 700);
			}
		}
		
		$key = 'videoHot_'.$p;
		if($uid < 0){
			$key = 'videoHot_'.$uid.'_'.$p;
		}
		
		$info = getcaches($key);
		if(!$info){
			$domain = new Domain_Video();
			$info   = $domain->getVideoList($uid, $p);
			if($info == 10010){
				return $this->success([], '暂无视频列表!');
			}
			
			setcaches($key, $info, 2);
		}
		
		return $this->success($info, '视频列表!');
	}
	
	/**
	 * 获取关注视频
	 * @desc 用于获取关注视频
	 * @return int code 操作码，0表示成功
	 * @return array info 视频列表
	 * @return array info[].userinfo 用户信息
	 * @return string info[].datetime 格式后的发布时间
	 * @return string info[].islike 是否点赞
	 * @return string info[].comments 评论总数
	 * @return string info[].likes 点赞数
	 * @return string msg 提示信息
	 */
	public function getAttentionVideo()
	{
		$uid        = checkNull($this->uid);
		$token      = checkNull($this->token);
		$p          = checkNull($this->p);
		$checkToken = checkToken($uid, $token);
		if($checkToken == 700){
			return $this->fail('您的登陆状态失效，请重新登陆！', $checkToken);
		}
		
		$key  = 'attention_vidseoLists_'.$uid.'_'.$p;
		$info = getcaches($key);
		if(!$info){
			$domain = new Domain_Video();
			$info   = $domain->getAttentionVideo($uid, $p);
			if($info == 0){
				return $this->success([], '暂无视频列表!');
			}
		}
		
		return $this->success($info, '视频列表!');
	}
	
	/**
	 * 视频详情
	 * @desc 用于获取视频详情
	 * @return int code 操作码，0表示成功，1000表示视频不存在
	 * @return array info[0] 视频详情
	 * @return object info[0].userinfo 用户信息
	 * @return string info[0].datetime 格式后的时间差
	 * @return string info[0].isattent 是否关注
	 * @return string info[0].likes 点赞数
	 * @return string info[0].comments 评论数
	 * @return string info[0].views 阅读数
	 * @return string info[0].steps 踩一踩数量
	 * @return string info[0].shares 分享数量
	 * @return string info[0].islike 是否点赞
	 * @return string info[0].isstep 是否踩
	 * @return string msg 提示信息
	 */
	public function getVideo()
	{
		$uid     = checkNull($this->uid);
		$videoid = checkNull($this->videoid);
		$domain  = new Domain_Video();
		$result  = $domain->getVideo($uid, $videoid);
		if($result == 1000){
			return $this->fail('视频已删除!', 1000);
			
		}
		
		return $this->success(['0' => $result]);
	}
	
	/**
	 * 视频评论列表
	 * @desc 用于获取视频评论列表
	 * @return int code 操作码，0表示成功
	 * @return array info
	 * @return string info[0].comments 评论总数
	 * @return array info[0].commentlist 评论列表
	 * @return object info[0].commentlist[].userinfo 用户信息
	 * @return string info[0].commentlist[].datetime 格式后的时间差
	 * @return string info[0].commentlist[].replys 回复总数
	 * @return string info[0].commentlist[].likes 点赞数
	 * @return string info[0].commentlist[].islike 是否点赞
	 * @return array info[0].commentlist[].replylist 回复列表
	 * @return string msg 提示信息
	 */
	public function getComments()
	{
		$uid     = checkNull($this->uid);
		$videoid = checkNull($this->videoid);
		$p       = checkNull($this->p);
		$isBan   = isBan($uid);
		if($isBan == '0'){
			return $this->fail('该账号已被禁用!', 700);
		}
		
		$domain = new Domain_Video();
		$result = $domain->getComments($uid, $videoid, $p);
		
		return $this->success(['0' => $result]);
	}
	
	/**
	 * 回复列表
	 * @desc 用于获取视频评论列表
	 * @return int code 操作码，0表示成功
	 * @return array info 评论列表
	 * @return object info[].userinfo 用户信息
	 * @return string info[].datetime 格式后的时间差
	 * @return object info[].tocommentinfo 回复的评论的信息
	 * @return object info[].tocommentinfo.content 评论内容
	 * @return string info[].likes 点赞数
	 * @return string info[].islike 是否点赞
	 * @return string msg 提示信息
	 */
	public function getReplys()
	{
		$uid       = checkNull($this->uid);
		$commentid = checkNull($this->commentid);
		$p         = checkNull($this->p);
		$isBan     = isBan($uid);
		if($isBan == '0'){
			return $this->fail('该账号已被禁用!', 700);
		}
		
		$domain = new Domain_Video();
		$info   = $domain->getReplys($uid, $commentid, $p);
		
		return $this->success($info);
	}
	
	
	/**
	 * 我的视频(弃用)
	 * @desc 用于获取我发布的视频
	 * @return int code 操作码，0表示成功
	 * @return array info 视频列表
	 * @return array info[].userinfo 用户信息
	 * @return string info[].datetime 格式后的发布时间
	 * @return string info[].islike 是否点赞
	 * @return string msg 提示信息
	 */
	public function getMyVideo()
	{
		$uid   = checkNull($this->uid);
		$token = checkNull($this->token);
		$p     = checkNull($this->p);
		
		$checkToken = checkToken($uid, $token);
		if($checkToken == 700){
			return $this->fail('您的登陆状态失效，请重新登陆！', $checkToken);
		}
		
		$domain = new Domain_Video();
		$info   = $domain->getMyVideo($uid, $p);
		
		return $this->success($info);
	}
	
	/**
	 * 删除视频
	 * @desc 用于删除视频以及相关信息
	 * @return int code 操作码，0表示成功
	 * @return string msg 提示信息
	 */
	public function del()
	{
		$uid     = checkNull($this->uid);
		$token   = checkNull($this->token);
		$videoid = checkNull($this->videoid);
		
		$checkToken = checkToken($uid, $token);
		if($checkToken == 700){
			return $this->fail('您的登陆状态失效，请重新登陆！', $checkToken);
		}
		
		$domain = new Domain_Video();
		$info   = $domain->del($uid, $videoid);
		
		return $this->success([], '删除成功!');
	}
	
	/**
	 * 举报视频
	 * @desc 用于举报视频
	 * @return int code 操作码，0表示成功
	 * @return string msg 提示信息
	 */
	public function report()
	{
		$uid     = checkNull($this->uid);
		$token   = checkNull($this->token);
		$videoid = checkNull($this->videoid);
		$content = checkNull($this->content);
		
		$checkToken = checkToken($uid, $token);
		if($checkToken == 700){
			return $this->fail('您的登陆状态失效，请重新登陆！', $checkToken);
		}
		
		$data   = array('uid' => $uid, 'videoid' => $videoid, 'content' => $content, 'addtime' => time(),);
		$domain = new Domain_Video();
		$info   = $domain->report($data);
		if($info == 1000){
			return $this->fail('视频不存在!', 1000);
		}
		
		return $this->success([], '举报成功!');
	}
	
	
	/**
	 * 个人主页视频
	 * @desc 用于获取个人主页视频
	 * @return int code 操作码，0表示成功
	 * @return string msg 提示信息
	 */
	public function getHomeVideo()
	{
		$uid   = checkNull($this->uid);
		$touid = checkNull($this->touid);
		$p     = checkNull($this->p);
		if($uid > 0){
			$isBan = isBan($uid);
			if($isBan == '0'){
				return $this->fail('该账号已被禁用!', 700);
			}
		}
		
		$domain = new Domain_Video();
		$info   = $domain->getHomeVideo($uid, $touid, $p);
		
		return $this->success($info);
	}
	
	/* 检测文件后缀 */
	protected function checkExt($filename)
	{
		$config = array("jpg", "png", "jpeg");
		$ext    = pathinfo(strip_tags($filename), PATHINFO_EXTENSION);
		
		return empty($config) ? true : in_array(strtolower($ext), $config);
	}
	
	/**
	 * 获取七牛上传Token
	 * @desc 用于获取七牛上传Token
	 * @return int code 操作码，0表示成功
	 * @return int code 操作码，0表示成功
	 * @return string msg 提示信息
	 */
	public function getQiniuToken()
	{
		//获取后台配置的腾讯云存储信息
		//$configPri=getConfigPri();
		
		//$token = DI()->qiniu->getQiniuToken2($configPri['qiniu_accesskey'],$configPri['qiniu_secretkey'],$configPri['qiniu_bucket']);
		$token = DI()->qiniu->getQiniuToken();
		
		return $this->success(['0' => ['token' => $token]]);
	}
	
	
	/**
	 * 获取附近的视频列表
	 * @desc 用于获取附近的视频列表
	 * @return int code 状态码，0表示成功
	 * @return string msg 提示信息
	 * @return array info 返回信息
	 */
	public function getNearby()
	{
		$uid = checkNull($this->uid);
		$lng = checkNull($this->lng);
		$lat = checkNull($this->lat);
		$p   = checkNull($this->p);
		if(($lng == '') || ($lat == '')){
			return $this->success();
		}
		if(!$p){
			$p = 1;
		}
		
		$key  = 'videoNearby_'.$lng.'_'.$lat.'_'.$p;
		$info = getcaches($key);
		if(!$info){
			$domain = new Domain_Video();
			$info   = $domain->getNearby($uid, $lng, $lat, $p);
			if($info == 1001){
				return $this->success();
			}
			
			setcaches($key, $info, 2);
		}
		
		return $this->success($info);
	}
	
	/**
	 * 获取视频举报分类列表
	 * @desc 获取视频举报分类列表
	 * @return int code 操作码，0表示成功
	 * @return string msg 提示信息
	 * @return array info 返回信息
	 */
	public function getReportContentlist()
	{
		$domain = new Domain_Video();
		$res    = $domain->getReportContentlist();
		if($res == 1001){
			return $this->fail('暂无举报分类列表!', 1001);
		}
		
		return $this->success($res);
	}
	
	/**
	 * 更新视频看完次数
	 * @desc 更新视频看完次数
	 * @return int code 操作码，0表示成功
	 * @return string msg 提示信息
	 * @return array info 返回信息
	 */
	public function setConversion()
	{
		$uid        = checkNull($this->uid);
		$token      = checkNull($this->token);
		$videoid    = checkNull($this->videoid);
		$random_str = checkNull($this->random_str);
		
		//md5加密验证字符串
		$str = md5($uid.'-'.$videoid.'-'.'#2hgfk85cm23mk58vncsark');
		if($random_str !== $str){
			return $this->fail('视频完整观看次数更新失败!', 1001);
		}
		
		$checkToken = checkToken($uid, $token);
		if($checkToken == 700){
			return $this->fail('您的登陆状态失效，请重新登陆！', $checkToken);
		}
		
		$domain = new Domain_Video();
		$res    = $domain->setConversion($videoid);
		
		return $this->success([], '视频完整观看次数更新成功!');
	}
	
	/**
	 * 获取分类下的视频
	 * @desc 获取分类下的视频
	 * @return int code 操作码 0表示成功
	 * @return string msg 提示信息
	 * @return array info
	 **/
	
	public function getClassVideo()
	{
		$videoclassid = checkNull($this->videoclassid);
		$uid          = checkNull($this->uid);
		$p            = checkNull($this->p);
		if(!$videoclassid){
			return $this->success();
		}
		
		$domain = new Domain_Video();
		$res    = $domain->getClassVideo($videoclassid, $uid, $p);
		
		return $this->success($res);
	}
	
	
	/**
	 * 用户开始观看视频
	 * @desc 用于每日任务统计用户观看时长
	 * @return int code 状态码，0表示成功
	 * @return string msg 提示信息
	 * @return array info 返回信息
	 */
	public function startWatchVideo()
	{
		$uid   = checkNull($this->uid);
		$token = checkNull($this->token);
		
		$checkToken = checkToken($uid, $token);
		if($checkToken == 700){
			return $this->fail('您的登陆状态失效，请重新登陆！', $checkToken);
		}
		
		$configpri        = getConfigPri();
		$dailytask_switch = $configpri['dailytask_switch'];
		if($dailytask_switch){
			//观看视频计时---每日任务
			$key  = 'watch_video_daily_tasks_'.$uid;
			$time = time();
			setcaches($key, $time);
		}
		
		return $this->success();
	}
	
	
	/**
	 * 用户结束观看视频
	 * @desc 用于每日任务统计用户观看时长
	 * @return int code 状态码，0表示成功
	 * @return string msg 提示信息
	 * @return array info 返回信息
	 */
	public function endWatchVideo()
	{
		$uid   = checkNull($this->uid);
		$token = checkNull($this->token);
		
		$checkToken = checkToken($uid, $token);
		if($checkToken == 700){
			return $this->fail('您的登陆状态失效，请重新登陆！', $checkToken);
		}
		
		/*观看视频计时---每日任务--取出用户起始时间*/
		$key       = 'watch_video_daily_tasks_'.$uid;
		$starttime = getcaches($key);
		if($starttime){
			$endtime = time();  //当前时间
			$data    = ['type' => '2', 'starttime' => $starttime, 'endtime' => $endtime,];
			dailyTasks($uid, $data);
			//删除当前存入的时间
			delcache($key);
		}
		
		return $this->success();
	}
	
	/**
	 * 删除评论
	 * @desc 用于删除评论以及子级评论
	 * @return int code 操作码，0表示成功
	 * @return string msg 提示信息
	 */
	public function delComments()
	{
		$uid        = checkNull($this->uid);
		$token      = checkNull($this->token);
		$videoid    = checkNull($this->videoid);
		$commentid  = checkNull($this->commentid);
		$commentuid = checkNull($this->commentuid);
		
		$checkToken = checkToken($uid, $token);
		if($checkToken == 700){
			return $this->fail('您的登陆状态失效，请重新登陆！', $checkToken);
		}
		
		$domain = new Domain_Video();
		$info   = $domain->delComments($uid, $videoid, $commentid, $commentuid);
		if($info == 1001){
			return $this->fail('视频信息错误,请稍后操作!', 1001);
		} elseif($info == 1002){
			return $this->fail('您无权进行删除操作!', 1002);
		}
		
		return $this->success([], '删除成功!');
	}
}
